/*
 * Copyright 2007-2009 Perttu "celeron55" Ahola <celeron55@gmail.com>
 *
 * This file is part of jukumagic.
 *
 * jukumagic is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * jukumagic is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with jukumagic.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef COMPONENT_H_
#define COMPONENT_H_

#include "common.h"
#include "jukuobject.h"
#include "footprint.h"

enum ComponentInfoType
{
	COMPONENT_INFO_NONE,
	COMPONENT_INFO_REFDES,
	COMPONENT_INFO_VALUE
};

class Component : public JukuObject
{
	Footprint *m_footprint;
	wxString m_refdes;
	wxString m_value;
	BoardPoint m_pos;
public:
	Component();
	~Component();
    JukuObjectType GetType(){ return TYPE_COMPONENT; }
	const wxChar * GetShortString(void){return m_refdes;}
	const wxChar * GetTypeString(void){return _("Component");}
	void WriteXML(TiXmlNode* root);
	static JukuObject* ReadFromXMLElement(TiXmlElement* element);
	void Draw(wxDC &dc, wxWindow *window, wxPoint origin);
	BoardRect GetDrawArea();
	
	BoardPoint GetBoardPos(){ return m_pos; }
	void SetBoardPos(BoardPoint p){ m_pos = p; ReportChange(OBJECT_CHANGE_CONTENTS); }
	void Move(int dx, int dy);

	wxString GetRefdes(){ return m_refdes; }
	void SetRefdes(wxString refdes){ m_refdes = refdes; ReportChange(OBJECT_CHANGE_CONTENTS); }

	wxString GetValue(){ return m_value; }
	void SetValue(wxString value){ m_value = value; ReportChange(OBJECT_CHANGE_CONTENTS); }

	bool IsSelectedInPoint(int x, int y);
	bool IsSelectedInArea(int x1, int y1, int x2, int y2, bool touch_is_enough);

	void SetSelected(bool selected);

	void Rotate(TurnDirection dir, BoardPoint origin);
	//void Rotate180();
	
	BoardRect GetPinExtents();

	void SetFootprint(Footprint *new_footprint);
	Footprint* GetFootprint();
	
	//moves unneeded offset from footprint to component coordinates
	void SimplifyCoordinates();
};

extern Component* MakeTwoWireComponent(FootprintType type,
		BoardPoint p1, BoardPoint p2, const wxString &refdes, const wxString &value);
	
#endif
